package org.paradise.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.paradise.dao.GexchangeDao;
import org.paradise.dao.GiftDao;
import org.paradise.pojo.Gexchange;
import org.paradise.pojo.Gift;
import org.paradise.pojo.Vip;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/gift")
public class GiftController {
    @Autowired
    private GiftDao giftDao;
    @Autowired
    private GexchangeDao gexchangeDao;
    /*显示礼品表的数据*/
    @RequestMapping("/list")
    @ResponseBody
    public Map<String,Object> list(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit, Gift gift) throws Exception{
        Map<String,Object> map=new HashMap<>();
        Page<Gift> pager= PageHelper.startPage(page,limit);
        List<Gift> list=giftDao.getList(gift);
        map.put("code",0);
        map.put("msg",null);
        map.put("data",list);
        map.put("count",pager.getTotal());
        return map;
    }

    /*增加礼品*/
    @RequestMapping("/add")
    @ResponseBody
    public Map<String,Object> add(Gift gift) throws Exception{
        Map<String,Object> map=new HashMap<>();
        giftDao.add(gift);
        return map;
    }
    /*删除礼品*/
    @RequestMapping("/del")
    @ResponseBody
    public Map<String,Object> add(Integer id) throws Exception{
        Map<String,Object> map=new HashMap<>();
        giftDao.delete(id);
        return map;
    }
    /*修改礼品*/
    @RequestMapping("/update")
    @ResponseBody
    public Map<String,Object> update(Gift gift) throws Exception{
        Map<String,Object> map=new HashMap<>();
        giftDao.update(gift);
        return map;
    }
    @RequestMapping("/batchupdate")
    @ResponseBody
    public Map<String,Object> batchupdate(Integer[] ids) throws Exception{
        Map<String,Object> map = new HashMap<>();
        giftDao.updatetotal(ids);
        map.put("result",true);
        return map;
    }
}
